<?php
	include_once 'Partial.class.php';
	include_once 'Helper.class.php';

	class View
	{
		public $Content = '';
		public $Css = array();
		public $Js = array();
		public $Layout;
		public $Route;
		public $Title = '';
		
		final public function __construct (  )
		{
			global $_ROUTE;
			$this->Route = $_ROUTE;
			$this->Layout = DEFAULT_LAYOUT;
		}
	
		final public function addCSS ( $src, $media = 'all' )
		{
			$temp['src'] = $src;
			$temp['media'] = $media;
			$this->Css[] = $temp;
		}
		
		final public function addJS ( $fullpath )
		{
			$this->Js[] = $fullpath;
		}
			
		final public function css()
		{
			$css_string = '';
		
			foreach( $this->Css as $stylesheet )
			{
				$css_string .= '<link rel="stylesheet" type="text/css" href="'. SITE_ADDRESS . $stylesheet['src'] . '" media="'.$stylesheet['media'].'" />';
			}
			echo $css_string;
		}
			
		final public function Display (  )
		{
			$this->setContent();
			include $this->Layout;
		}

		final public function DisplayError ( $errorname = 'fourohfour' )
		{
			#ERROR MESSAGE HANDLER
			$this->setErrorContent( $errorname );
			include $this->Layout;
		}

		final public function setLayout ( $relative_path )
		{
			$this->Layout = LAYOUT_PATH . $relative_path;
		}
		
		final public function setTitle ( $title )
		{
			$this->Title = $title;
		}
			
		# -------------------------------------------------------------------------------------
	
		final private function partial ( $filename = '', $data )
		{				
			$file_path = APPLICATION_PATH.$this->Route->folder.'/view/partials/'.$filename.'.partial.php';
			
			$partial = new Partial( $file_path, $data );
			
			return $partial->Content;
		}
		
		final private function helper ()
		{
			$this->Helper = new Helper();
			return $this->Helper;
		}
	
		final private function setContent (  )
		{
			ob_start(); 	
			include APPLICATION_PATH.$this->Route->folder.'/view/scripts/'.$this->Route->controller.'/'.$this->Route->action.'.view.php';
			$this->Content = ob_get_contents(); 
			ob_end_clean(); 
		}

		final private function setErrorContent ( $errorname = 'fourohfour' )
		{
			ob_start(); 	
			include ERROR_PATH."$errorname.error.php";
			$this->Content = ob_get_contents(); 
			ob_end_clean(); 
		}
	
	}
?>
